package lesson14.protobuf;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.*;

/**
 * <br/>
 * Created on : 2018-02-28 23:06
 * @author lizebin
 */
public class ClientInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();

		//声明数据类型
		pipeline.addLast(new ProtobufDecoder(Sinoxk.Message.getDefaultInstance()));
		pipeline.addLast(new ProtobufEncoder());
		pipeline.addLast(new ProtobufVarint32FrameDecoder());
		pipeline.addLast(new ProtobufVarint32LengthFieldPrepender());

		pipeline.addLast(new ClientHandler());
	}
}
